﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using InformationSystem.BLL.Core.Service;
using InformationSystem.BLL.Core.Model;
using Ext.Net;

namespace InformationSystem.WebSite.Module.SecurityMgr
{
    public partial class passwordchange : BasePage
    {
        public IUserService UserService;

        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void ChangeBtn_Click(object sender, EventArgs e)
        {
            LoginUser user = (LoginUser)Session["LoginUser"];
            string oldpwd = this.oldpwd.Text;
            string newpwd = this.newpwd.Text;
            string renewpwd = this.renewpwd.Text;
            if (oldpwd == ""||newpwd == ""||renewpwd == "")
            {
                X.Msg.Show(new MessageBoxConfig
                {
                    Buttons = MessageBox.Button.OK,
                    Icon = MessageBox.Icon.INFO,
                    Title = "信息",
                    Message = "原密码、新密码、确认密码均不能为空！"
                });
                return;
                
            }
            if (newpwd != renewpwd)
            {
                X.Msg.Show(new MessageBoxConfig
                {
                    Buttons = MessageBox.Button.OK,
                    Icon = MessageBox.Icon.INFO,
                    Title = "信息",
                    Message = "新密码和确认密码必须一致！"
                });
                return;
            }
            
           bool result= UserService.ChangePassword(user,oldpwd, newpwd);

           if (result)
           {
               X.Msg.Show(new MessageBoxConfig
               {
                   Buttons = MessageBox.Button.OK,
                   Icon = MessageBox.Icon.INFO,
                   Title = "信息",
                   Message = "修改成功！"
               });
               return;

           }
           else
           {
               X.Msg.Show(new MessageBoxConfig
               {
                   Buttons = MessageBox.Button.OK,
                   Icon = MessageBox.Icon.INFO,
                   Title = "信息",
                   Message = "修改失败！"
               });
               return;
           }
           




        }
        protected void CancelBtn_Click(object sender, EventArgs e)
        { 
        
        }

        protected override bool CommitPermissionCheck()
        {
            throw new NotImplementedException();
        }
    }
}